(function(doc, win) {
        var docEl = doc.documentElement,
        resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
        recalc = function() {
            // 设计稿的宽高
			const defWidth = 1920;
			const defHeight = 1080;
            const pcH = docEl.clientHeight;
			const pcW= docEl.clientWidth;

            const flag = pcH / pcW < defHeight / defWidth
			const dom = document.getElementById('app');
            
            dom.style.width = defWidth + 'px';
			dom.style.height = defHeight + 'px';
            const scale = flag ? pcH / defHeight : pcW / defWidth;
			dom.style.transform = `scale(${scale})`
			const top = flag ? - (defHeight * (1 - scale)) / 2 : -((defHeight * (1 - scale)) / 2 - (pcH - defHeight * scale) / 2);
			const left = flag ? - ((defWidth * (1 - scale)) / 2 - (pcW - defWidth * scale) / 2) : -(defWidth * (1 - scale)) / 2;

            dom.style.top = `${top}px`;
			dom.style.left = `${left}px`;
        };

    if (!doc.addEventListener) return;
    win.addEventListener(resizeEvt, recalc, false);
    doc.addEventListener('DOMContentLoaded', recalc, false);
})(document, window);



function ajax(option) {
    function conStr(params) {
        var str = "";
        for (var obj in params) {
            //对中文进行编码
            str += obj + "=" + encodeURI(params[obj]) + "&";
        }
        return str.slice(0, -1);
    }
    var xhr = new XMLHttpRequest;
    option.type = option.type || "get";
    if (option.type == "get") {
        if (option.data) {
            option.url = option.url + "?" + conStr(option.data);
        }
        xhr.open(option.type, option.url);
        xhr.send();
        xhr.onreadystatechange = function() {
            if (this.readyState === 4) {
                option.success(JSON.parse(this.response));
            }
        }
    }
    if (option.type == "post") {
        xhr.open(option.type, option.url);
        //当请求的数据类型是否传参时，需要设置默认值，默认值的书写
        xhr.setRequestHeader("Content-Type", option.contentType || "application/x-www-form-urlencoded");
        xhr.onreadystatechange = function() {
            if (this.readyState === 4) {
                if (option.dataType == "json") {
                    option.success(JSON.parse(this.response));
                } else {
                    option.success(this.response);
                }
            }
        }
        if (option.data) {
            if (option.contentType == "application/json") {
                //当请求的数据类型规定为json数据的时候，需要将数据类型转换为json字
                //因为请求的数据本身是对象类型
                xhr.send(JSON.stringify(option.data));
            } else {
                //post请求时，默认传递的数据是字符串拼接起来的
                xhr.send(conStr(option.data));
            }
        } else {
            xhr.send();
        }
    }
}